package com.itcast.admin.controller;

import com.itcast.common.annotation.IgnoreToken;
import com.itcast.common.model.dto.request.CheckGroupAddReqDTO;
import com.itcast.common.model.dto.request.CheckGroupPullReqDTO;
import com.itcast.common.model.dto.request.CheckGroupReqDTO;
import com.itcast.common.model.dto.response.CheckGroupListResDTO;
import com.itcast.common.model.dto.response.CheckGroupResDTO;
import com.itcast.security.model.Checkgroup;
import com.itcast.security.service.ICheckGroupService;
import com.jzo2o.common.model.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("checkGroupController")
@RequestMapping("/admin/check-group")
@Api(tags = "管理端 --体检组相关接口")
@RequiredArgsConstructor
public class CheckGroupController {

    private final ICheckGroupService checkGroupService;

    @GetMapping("/pageQuery")
    @ApiOperation("体检组分页查询")
    public PageResult<CheckGroupResDTO> page(CheckGroupReqDTO servePageQueryReqDTO) {
        PageResult<CheckGroupResDTO> list = checkGroupService.queryList(servePageQueryReqDTO);
        return list;
    }
    /**
     * 新增体检组
     */
    @PostMapping
    @ApiOperation("新增体检组")
    public Checkgroup add(@RequestBody @Validated CheckGroupAddReqDTO checkGroupReqDTO){
        return checkGroupService.add(checkGroupReqDTO);
    }


    /**
     * 根据ID查询体检组信息
     */
    @GetMapping("/{id}")
    @ApiOperation("根据ID查询体检组信息")
    public Checkgroup getById(@PathVariable Long id){
        return checkGroupService.getById(id);
    }


    /**
     * 修改体检组信息
     */
    @PutMapping("/{id}")
    @ApiOperation("修改体检组信息")
    public Checkgroup update(@PathVariable Long id, @RequestBody @Validated CheckGroupAddReqDTO checkGroupAddReqDTO){
        Checkgroup checkgroup = checkGroupService.updateCheckGroup(id, checkGroupAddReqDTO);
        return checkgroup;
    }

    /**
     * 启用
     */
    @PutMapping("/enable/{id}")
    @ApiOperation("启用")
    public Checkgroup enable(@PathVariable Long id){
        return checkGroupService.oNStatus(id);
    }

    /**
     * 根据id判断是否可以禁用
     */
    @GetMapping("/checkDisable/{id}")
    @ApiOperation("根据id判断是否可以禁用")
    public Checkgroup check(@PathVariable Long id){
        //todo : 写完套餐在来写
        return null;
    }

    /**
     * 根据id禁用检查组
     */
    @PutMapping("/disable/{id}")
    @ApiOperation("根据id禁用检查组")
    @IgnoreToken
    public Checkgroup disable(@PathVariable Long id){
        //todo 写完套餐再写
        return checkGroupService.offStatus(id);
    }

    /**
     * 删除检查组
     */

    @DeleteMapping("/{id}")
    @ApiOperation("删除检查组")
    public boolean delete(@PathVariable Long id){
        return checkGroupService.removeCheckGroup(id);
    }

    /**
     * 体检组下拉列表
     */
    @GetMapping("/listForFilter")
    @ApiOperation("体检组下拉列表")
    public List<CheckGroupListResDTO> selectList(@Validated CheckGroupPullReqDTO checkGroupPullReqDTO){
        List<CheckGroupListResDTO> list = checkGroupService.queryCheckList(checkGroupPullReqDTO);
        return list;
    }

}
